package utils

import (
	"longmen/server/config/global"
	"longmen/server/pkg/common/api_models"
	"longmen/server/pkg/common/services"
)

func getGift(giftId int) (giftType, giftPrice int) {

	rs, err := services.GetGiftList()
	if err != nil {
		return 0, 0
	}
	for _, v := range rs {
		if v.Id == giftId {
			return v.PriceType, v.Price
		}

	}
	return 0, 0
}

func GetGiftPrice(roomCfg *api_models.LiveConfigResp, giftId, count int) (int, int, error) {
	giftType, unitPrice := getGift(giftId)
	if giftType == 0 || unitPrice == 0 {
		global.Log.Errorf("room[%d]: send gift %d(%d) price(%d) ", roomCfg.Liveid, giftId, giftType, unitPrice)
		return 0, 0, nil
	}
	// 单价/100 * 数量
	// 单价 10克拉 = 1000 （需要给去除一下）
	giftPrice := (unitPrice / 100) * count
	return giftType, giftPrice, nil
}
